import 'package:flutter/material.dart';

class SwitchAndCheckBoxTestRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: new Text("单选框和复选框")),
      body: new SwitchAndCheckBoxTest(),
    );
  }
}

class SwitchAndCheckBoxTest extends StatefulWidget {
  @override
  _SwitchAndCheckBoxTest createState() => new _SwitchAndCheckBoxTest();
}

class _SwitchAndCheckBoxTest extends State<SwitchAndCheckBoxTest> {
  //定义开关的状态
  bool _switchSelected = true;
  bool _checkboxSelected = true; //维护复选框状态
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Switch(
            value: _switchSelected,
            onChanged: (value) {
              setState(() {
                _switchSelected = value;
              });
            }),
        Checkbox(
            value: _checkboxSelected,
            activeColor: Colors.red, //选中时的颜色
            onChanged: (value) {
              setState(() {
                _checkboxSelected = value;
              });
            })
      ],
    );
  }
}
